//
//  APPLEWelcomeViewController.swift
//  123
//
//  Created by pangjiaxing on 15/12/31.
//  Copyright © 2015年 pangjiaxing. All rights reserved.
//

import UIKit
import SDWebImage
import SnapKit
class APPLEWelcomeViewController: UIViewController {
    private lazy var headImage :UIImageView = {
        let result = UIImageView()
        result.layer.cornerRadius=45
        result.layer.masksToBounds=true
        return result
    }()
    private lazy var messageLabel :UILabel = {
        let label=UILabel()
        label.text = "欢迎归来"
        label.alpha = 0
        return label
    }()
    override func viewDidLoad() {
        super.viewDidLoad()

        if let headImageUrlString = APPLEUserAccountViewModel.sharedViewModel.userAccount?.avatar_large {
           headImage.sd_setImageWithURL(NSURL(string: headImageUrlString), placeholderImage: UIImage(named: "avatar_default_big"))
            
        }
        setUpUI()
    }
    private func setUpUI(){
        view.backgroundColor = UIColor(white: 247/255, alpha: 1)
        view.addSubview(headImage)
        view.addSubview(messageLabel)
       
        headImage.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(200)
            make.size.equalTo(CGSizeMake(80, 80))
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headImage.snp_bottom).offset(10)
            make.centerX.equalTo(headImage)
        }
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        headImage.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(view).offset(100)
        }
    
       UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
        self.view.layoutIfNeeded()
        }) { (_) -> Void in
            
            UIView.animateWithDuration(1, animations: { () -> Void in
                
                self.messageLabel.alpha=1
                }, completion: { (_) -> Void in
                print("APPLEWelcomeViewController已经表演完动画，准备跳转控制器")
            NSNotificationCenter.defaultCenter().postNotificationName("HMSwitchRootViewControllerNotification", object: nil)
                    
            })
        }
    }
  
}
